import dataList from "@/components/dataList";
import { fetchList } from "../../api/lessor-refund";

export default {
    name: "resource-manage",
    components: { dataList },
    provide() {
        return {
            initList: this.getListData
        };
    },
     beforeMount() {
        this.getListData();
    },
    data() {
        return {
            tableData: [],
            // 请求参数
            params: {
                current: 1,
                size: 20,
                projectName: ""
            },
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 页面loading
            loading: false,
            filterList: [
                {
                    label: "付款项目",
                    inputType: "dict",
										dictName: "charge_project_type_lessor",
                    name: "chargeProjectName",
                    multiple: true
                },
                {
                    label: "最小退款金额",
                    inputType: "input",
                    name: "refundAmountStart"
                },
                {
                    label: "最大退款金额",
                    inputType: "input",
                    name: "refundAmountEnd"
                }
            ]
        };
    },
    filters: {
        mySubString(val) {
            if (val != null) {
                return val.substring(0, 7);
            }
            return "";
        }
    },
    methods: {
        getListData(params = {}) {
            this.loading = true;
            let requestData = { ...this.params, ...params };
            fetchList(requestData)
                .then(res => {
                    const { current, size, total, records } = res.data.data;
                    this.tableData = records;
                    this.params = requestData;
                    this.pager = { total, current, size };
                })
                .finally(() => {
                    this.loading = false;
                });
        },
        downloadData() {
            if (this.tableData.length) {
                this.publicExport('押金台账','/api/lessorrefund/downloadExcel',this.params)
            } else {
                this.$message.error(
                    "暂无数据导出！请选择筛选条件查出数据后进行导出！"
                );
            }
        },
        // 菜单点击监听
        handleMenuClick(type) {
            switch (type) {
                case "export":
                    this.downloadData();
                    break;
                default:
                    this.$message(type);
                    break;
            }
        }
    }
};
